package model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.ArrayList;
import physics.Circle;
import physics.Geometry;
import physics.Vect;


public class CircleBumper implements IGizmo {
	
	private String name;
	private int L;
	private int x;
	private int y;
	private Color col;
	private Circle shape;
	private Vect reflection = null;
	
	
	public CircleBumper(int gridL) {
		L = gridL;
		col = new Color(0x00C000);
	}
	
	public CircleBumper(int gridL, String s) {
		name = s;
		L = gridL;
		col = new Color(0x00C000);
	}
		
	public void setPosition(int xpos, int ypos) {
		x = xpos*L;
		y = ypos*L;
		shape = new Circle(x+L/2, y+L/2, L/2);
	}
	
	@Override
	public void addLinkedGizmo(IGizmo giz) {
		// TODO Auto-generated method stub
	}	
	
	@Override
	public void addLinkedKey(int key) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void doLinkedAction() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Rectangle getBounds() {
		return new Rectangle(x, y, L, L);
	}

	@Override
	public Color getColor() {
		return col;
	}

	@Override
	public ArrayList<IGizmo> getLinkedGizmos() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Integer> getLinkedKeys() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getType() {
		return "Circle";
	}

	@Override
	public int getX() {
		return x;
	}

	@Override
	public int getY() {
		return y;
	}

	@Override
	public Graphics paintShape(Graphics g) {
		g.setColor(col);
		g.fillOval(x, y, L, L); 
		return g;
	}

	@Override
	public void rotateClockwise() {
		//no need
	}

	@Override
	public void setColor(Color col) {
		this.col = col;
	}

	@Override
	public void triggerEvent() {
		int c = col.getRGB();
		col = new Color(c+255);
	}

	@Override
	public double timeUntilCollision(Ball ball) {
		return Geometry.timeUntilCircleCollision(shape, ball.getCircle(), ball.getV());
	}

	@Override
	public Vect reflectionVector(Ball ball) {
		return Geometry.reflectCircle(shape.getCenter(), ball.getCircle().getCenter(), ball.getV());
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public int getTriangleRotations() {
		// TODO Auto-generated method stub
		return 0;
	}
}